<?php
 function delete($tbl,$id=null,$where=null)
 {
   $where=$where==null?'':'where'.$id.'='.$where;
  $sql="delete from {$tbl}{$id}{$where}";
   $res=musql_query($sql);
if($res){
	return mysql_affected_rows();
}
else{
	return false;
}

 }
function update($tbl,$data,$where=null){
	foreach ($data as $key => $val) {
		$sets.=$key."='".$val."',";
	}
	$sets=rtrim($sets,',');
	$where=$where==null?'':'WHERE '.$where;
	$sql="update {$tbl} set {$sets} {$where}";
    echo $sql;

    /*$result=mysql_query($sql);
    if($result){
    	return mysql_affected_rows();
    }
    else {
    	return false;
    }*/

}
$table="users";
$data=array("id"=>2,"username"=>"test","age"=>"15");
$where="id=2";
update($table,$data,$where);



function add($tbl,$data){
	$keys=implode(',',array_keys($data));
	$values=implode("','",array_values($data));
	$sql="insert into {$tbl}({$keys}) values ('{$values}')";
/*	$result=mysql_query($sql);
	if($result===FALSE){
		return false;
	}
	else{
		return mysql_insert_id();
*/}
	$tbl="users";
    $data=array("id"=>2,"username"=>"test","age"=>"15");

    add($tbl,$data);


 ?>